/*
 * ER/Studio 7.5 SQL Code Generation
 * Company :      Microsoft
 * Project :      SubsidiosModels.DM1
 * Author :       Microsoft
 *
 * Date Created : Tuesday, November 24, 2009 01:14:27
 * Target DBMS : Microsoft SQL Server 2005
 */

/* 
 * TABLE: Alcance 
 */

CREATE TABLE Alcance(
    AlcanceId       int            IDENTITY(1,1),
    Descripcion     varchar(60)    NOT NULL,
    ExpedienteId    int            NULL,
    CONSTRAINT PK13 PRIMARY KEY NONCLUSTERED (AlcanceId)
)
go



IF OBJECT_ID('Alcance') IS NOT NULL
    PRINT '<<< CREATED TABLE Alcance >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Alcance >>>'
go

/* 
 * TABLE: Beneficiario 
 */

CREATE TABLE Beneficiario(
    BeneficiarioId        int        IDENTITY(1,1),
    NroDoc                int        NOT NULL,
    EnteId                int        NULL,
    Excedido              char(1)    NOT NULL,
    TipoBeneficiarioId    int        NOT NULL,
    CONSTRAINT PK2 PRIMARY KEY NONCLUSTERED (BeneficiarioId, NroDoc)
)
go



IF OBJECT_ID('Beneficiario') IS NOT NULL
    PRINT '<<< CREATED TABLE Beneficiario >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Beneficiario >>>'
go

/* 
 * TABLE: [Beneficiario Expediente] 
 */

CREATE TABLE [Beneficiario Expediente](
    BeneficiarioId    int    NOT NULL,
    NroDoc            int    NOT NULL,
    ExpedienteId      int    NOT NULL,
    CONSTRAINT PK12 PRIMARY KEY NONCLUSTERED (BeneficiarioId, NroDoc, ExpedienteId)
)
go



IF OBJECT_ID('Beneficiario Expediente') IS NOT NULL
    PRINT '<<< CREATED TABLE Beneficiario Expediente >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Beneficiario Expediente >>>'
go

/* 
 * TABLE: Bloque 
 */

CREATE TABLE Bloque(
    BloqueId       int            IDENTITY(1,1),
    Descripcion    varchar(60)    NOT NULL,
    CONSTRAINT PK14 PRIMARY KEY NONCLUSTERED (BloqueId)
)
go



IF OBJECT_ID('Bloque') IS NOT NULL
    PRINT '<<< CREATED TABLE Bloque >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Bloque >>>'
go

/* 
 * TABLE: Ente 
 */

CREATE TABLE Ente(
    EnteId         int            IDENTITY(1,1),
    RazonSocial    varchar(60)    NOT NULL,
    CONSTRAINT PK3 PRIMARY KEY NONCLUSTERED (EnteId)
)
go



IF OBJECT_ID('Ente') IS NOT NULL
    PRINT '<<< CREATED TABLE Ente >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Ente >>>'
go

/* 
 * TABLE: Expediente 
 */

CREATE TABLE Expediente(
    ExpedienteId              int            IDENTITY(1,1),
    FuncionarioId             int            NOT NULL,
    NroExpediente             varchar(60)    NOT NULL,
    FechaCaratulacion         datetime       NOT NULL,
    TipoEstadoExpedienteId    int            NULL,
    CONSTRAINT PK11 PRIMARY KEY NONCLUSTERED (ExpedienteId)
)
go



IF OBJECT_ID('Expediente') IS NOT NULL
    PRINT '<<< CREATED TABLE Expediente >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Expediente >>>'
go

/* 
 * TABLE: Funcionario 
 */

CREATE TABLE Funcionario(
    SenadorId            int    IDENTITY(1,1),
    EnteId               int    NULL,
    BloqueId             int    NULL,
    TipoFuncionarioId    int    NOT NULL,
    CONSTRAINT PK1 PRIMARY KEY NONCLUSTERED (SenadorId)
)
go



IF OBJECT_ID('Funcionario') IS NOT NULL
    PRINT '<<< CREATED TABLE Funcionario >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Funcionario >>>'
go

/* 
 * TABLE: MontoPresupuesto 
 */

CREATE TABLE MontoPresupuesto(
    MontoPresupuestoId    int      IDENTITY(1,1),
    MontoMaximo           money    NOT NULL,
    CONSTRAINT PK16 PRIMARY KEY NONCLUSTERED (MontoPresupuestoId)
)
go



IF OBJECT_ID('MontoPresupuesto') IS NOT NULL
    PRINT '<<< CREATED TABLE MontoPresupuesto >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE MontoPresupuesto >>>'
go

/* 
 * TABLE: Movimiento 
 */

CREATE TABLE Movimiento(
    MovimientoId    int         IDENTITY(1,1),
    FechaSalida     datetime    NOT NULL,
    OficinaId       int         NOT NULL,
    ExpedienteId    int         NULL,
    CONSTRAINT PK18 PRIMARY KEY NONCLUSTERED (MovimientoId)
)
go



IF OBJECT_ID('Movimiento') IS NOT NULL
    PRINT '<<< CREATED TABLE Movimiento >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Movimiento >>>'
go

/* 
 * TABLE: Oficina 
 */

CREATE TABLE Oficina(
    OficinaId      int             IDENTITY(1,1),
    Descripcion    varchar(100)    NOT NULL,
    CONSTRAINT PK19 PRIMARY KEY NONCLUSTERED (OficinaId)
)
go



IF OBJECT_ID('Oficina') IS NOT NULL
    PRINT '<<< CREATED TABLE Oficina >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Oficina >>>'
go

/* 
 * TABLE: Solicitud 
 */

CREATE TABLE Solicitud(
    SolicitudId     int      NOT NULL,
    Monto           money    NOT NULL,
    ExpedienteId    int      NOT NULL,
    CONSTRAINT PK9 PRIMARY KEY NONCLUSTERED (SolicitudId)
)
go



IF OBJECT_ID('Solicitud') IS NOT NULL
    PRINT '<<< CREATED TABLE Solicitud >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Solicitud >>>'
go

/* 
 * TABLE: Subsidio 
 */

CREATE TABLE Subsidio(
    SubsidioId     int    IDENTITY(1,1),
    SolicitudId    int    NULL,
    CONSTRAINT PK4 PRIMARY KEY NONCLUSTERED (SubsidioId)
)
go



IF OBJECT_ID('Subsidio') IS NOT NULL
    PRINT '<<< CREATED TABLE Subsidio >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Subsidio >>>'
go

/* 
 * TABLE: Subvencion 
 */

CREATE TABLE Subvencion(
    SubvencionId    int         IDENTITY(1,1),
    FechaInicio     datetime    NOT NULL,
    FechaFin        datetime    NOT NULL,
    CantCuotas      int         NOT NULL,
    SolicitudId     int         NULL,
    CONSTRAINT PK6 PRIMARY KEY NONCLUSTERED (SubvencionId)
)
go



IF OBJECT_ID('Subvencion') IS NOT NULL
    PRINT '<<< CREATED TABLE Subvencion >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Subvencion >>>'
go

/* 
 * TABLE: TipoBeneficiario 
 */

CREATE TABLE TipoBeneficiario(
    TipoBeneficiarioId    int            IDENTITY(1,1),
    MontoMaximo           money          NOT NULL,
    Descripcion           varchar(60)    NOT NULL,
    CONSTRAINT PK7 PRIMARY KEY NONCLUSTERED (TipoBeneficiarioId)
)
go



IF OBJECT_ID('TipoBeneficiario') IS NOT NULL
    PRINT '<<< CREATED TABLE TipoBeneficiario >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE TipoBeneficiario >>>'
go

/* 
 * TABLE: TipoEstadoExpediente 
 */

CREATE TABLE TipoEstadoExpediente(
    TipoEstadoExpedienteId    int            IDENTITY(1,1),
    Descripcion               varchar(60)    NOT NULL,
    CONSTRAINT PK15 PRIMARY KEY NONCLUSTERED (TipoEstadoExpedienteId)
)
go



IF OBJECT_ID('TipoEstadoExpediente') IS NOT NULL
    PRINT '<<< CREATED TABLE TipoEstadoExpediente >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE TipoEstadoExpediente >>>'
go

/* 
 * TABLE: TipoFuncionario 
 */

CREATE TABLE TipoFuncionario(
    TipoFuncionarioId     int            IDENTITY(1,1),
    Descripcion           varchar(60)    NOT NULL,
    MontoPresupuestoId    int            NOT NULL,
    CONSTRAINT PK17 PRIMARY KEY NONCLUSTERED (TipoFuncionarioId)
)
go



IF OBJECT_ID('TipoFuncionario') IS NOT NULL
    PRINT '<<< CREATED TABLE TipoFuncionario >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE TipoFuncionario >>>'
go

/* 
 * TABLE: Alcance 
 */

ALTER TABLE Alcance ADD CONSTRAINT RefExpediente20 
    FOREIGN KEY (ExpedienteId)
    REFERENCES Expediente(ExpedienteId)
go


/* 
 * TABLE: Beneficiario 
 */

ALTER TABLE Beneficiario ADD CONSTRAINT RefEnte2 
    FOREIGN KEY (EnteId)
    REFERENCES Ente(EnteId)
go

ALTER TABLE Beneficiario ADD CONSTRAINT RefTipoBeneficiario6 
    FOREIGN KEY (TipoBeneficiarioId)
    REFERENCES TipoBeneficiario(TipoBeneficiarioId)
go


/* 
 * TABLE: [Beneficiario Expediente] 
 */

ALTER TABLE [Beneficiario Expediente] ADD CONSTRAINT RefBeneficiario16 
    FOREIGN KEY (BeneficiarioId, NroDoc)
    REFERENCES Beneficiario(BeneficiarioId, NroDoc)
go

ALTER TABLE [Beneficiario Expediente] ADD CONSTRAINT RefExpediente17 
    FOREIGN KEY (ExpedienteId)
    REFERENCES Expediente(ExpedienteId)
go


/* 
 * TABLE: Expediente 
 */

ALTER TABLE Expediente ADD CONSTRAINT RefTipoEstadoExpediente22 
    FOREIGN KEY (TipoEstadoExpedienteId)
    REFERENCES TipoEstadoExpediente(TipoEstadoExpedienteId)
go


/* 
 * TABLE: Funcionario 
 */

ALTER TABLE Funcionario ADD CONSTRAINT RefEnte1 
    FOREIGN KEY (EnteId)
    REFERENCES Ente(EnteId)
go

ALTER TABLE Funcionario ADD CONSTRAINT RefBloque21 
    FOREIGN KEY (BloqueId)
    REFERENCES Bloque(BloqueId)
go

ALTER TABLE Funcionario ADD CONSTRAINT RefTipoFuncionario24 
    FOREIGN KEY (TipoFuncionarioId)
    REFERENCES TipoFuncionario(TipoFuncionarioId)
go


/* 
 * TABLE: Movimiento 
 */

ALTER TABLE Movimiento ADD CONSTRAINT RefOficina27 
    FOREIGN KEY (OficinaId)
    REFERENCES Oficina(OficinaId)
go

ALTER TABLE Movimiento ADD CONSTRAINT RefExpediente28 
    FOREIGN KEY (ExpedienteId)
    REFERENCES Expediente(ExpedienteId)
go


/* 
 * TABLE: Solicitud 
 */

ALTER TABLE Solicitud ADD CONSTRAINT RefExpediente19 
    FOREIGN KEY (ExpedienteId)
    REFERENCES Expediente(ExpedienteId)
go


/* 
 * TABLE: Subsidio 
 */

ALTER TABLE Subsidio ADD CONSTRAINT RefSolicitud13 
    FOREIGN KEY (SolicitudId)
    REFERENCES Solicitud(SolicitudId)
go


/* 
 * TABLE: Subvencion 
 */

ALTER TABLE Subvencion ADD CONSTRAINT RefSolicitud14 
    FOREIGN KEY (SolicitudId)
    REFERENCES Solicitud(SolicitudId)
go


/* 
 * TABLE: TipoFuncionario 
 */

ALTER TABLE TipoFuncionario ADD CONSTRAINT RefMontoPresupuesto25 
    FOREIGN KEY (MontoPresupuestoId)
    REFERENCES MontoPresupuesto(MontoPresupuestoId)
go


